﻿using NLog;
using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebAppWeChatDemo.Common
{
    public class ReportJobScheduler
    {
        private static IScheduler scheduler;
        private static Logger logger = LogManager.GetCurrentClassLogger();
        public static void Start()
        {
            logger.Info("启动定时器");
            scheduler = StdSchedulerFactory.GetDefaultScheduler();
            scheduler.Start();
            IJobDetail job = JobBuilder.Create<SendMessageJob>().Build();
            ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity("triggerSendMessage", "groupWeChart")
                .WithSimpleSchedule(t =>
                  t.WithIntervalInSeconds(5)
                   .RepeatForever())
                .Build();
            scheduler.ScheduleJob(job, trigger);
        }

        public static void Shutdown()
        {
            if(null != scheduler)
            {
                logger.Info("关闭定时器");
                scheduler.Shutdown();
            }
        }
    }
}